package com.study.lxy.util;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanDefinitionRegistryPostProcessor;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.stereotype.Component;

import java.util.ArrayList;

@Component
public class MyBeanDefinitionRegistryPostProcessor implements BeanDefinitionRegistryPostProcessor {
    public void postProcessBeanDefinitionRegistry(BeanDefinitionRegistry registry) throws BeansException {
        GenericBeanDefinition genericBeanDefinition = new GenericBeanDefinition();
        genericBeanDefinition.setBeanClass(ArrayList.class);
        genericBeanDefinition.setSynthetic(true);
        registry.registerBeanDefinition("myArrayList",genericBeanDefinition);
        // 测试是否可以将ImportBeanDefinitionRegistrar中的处理放到此处，证明是可行的
        // 但是两者的执行时机分别是什么时候呢？这个可以具体深入一下
        // 实际上ImportBeanDefinitionRegistrar使用起来比较麻烦，需要在Config类中使用@import引入才能生效
        MyCompentAutoScanner myCompentAutoScanner = new MyCompentAutoScanner(registry,false);
        myCompentAutoScanner.doFilter();
        myCompentAutoScanner.doScan("com.study.lxy");
    }

    public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

    }
}
